package com.wgts.wgts.mvp.view.activity.mycenter;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.wgts.wgts.R;
import com.wgts.wgts.base.BaseActivity;
import com.wgts.wgts.control.toast.MoHuToast;
import com.wgts.wgts.mvp.view.activity.webactivity.WebActivity;
import com.wgts.wgts.tools.MoHuGlide;
import com.wgts.wgts.tools.Tools;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/*
 *
 *
 *   data:2018/9/2910:20
 *
 */public class AboutPlatformActivity extends BaseActivity {
    @BindView(R.id.back_btn_image)
    ImageView backBtnImage;
    @BindView(R.id.back_btn_ly)
    LinearLayout backBtnLy;
    @BindView(R.id.include_title)
    TextView includeTitle;
    @BindView(R.id.include_text)
    TextView includeText;
    @BindView(R.id.include_right_image)
    ImageView includeRightImage;
    @BindView(R.id.include_right_ly)
    LinearLayout includeRightLy;
    @BindView(R.id.platform_log)
    ImageView platformLog;
    @BindView(R.id.platform_version)
    TextView platformVersion;
    @BindView(R.id.copy_phone)
    TextView copyPhone;
    @BindView(R.id.platform_phone)
    TextView platformPhone;
    @BindView(R.id.call_platform_ly)
    RelativeLayout callPlatformLy;
    @BindView(R.id.platform_agreement_ly)
    RelativeLayout platformAgreementLy;
    @BindView(R.id.platform_image)
    ImageView platformImage;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_center_about_platform_activity);
        ButterKnife.bind(this);
        includeTitle.setText("关于微广");
        PackageManager manager = this.getPackageManager();
        PackageInfo info = null;
        try {
            info = manager.getPackageInfo(getPackageName(), 0);
            platformVersion.setText("微广V" + info.versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        initView();
    }

    @Override
    public void init() {

    }

    private void initView() {
        saveImage();
    }

    @OnClick({R.id.back_btn_ly, R.id.call_platform_ly, R.id.platform_agreement_ly})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_btn_ly:
                finish();
                break;
            case R.id.call_platform_ly:
                copy(platformPhone);
                break;
            case R.id.platform_agreement_ly:
                Intent intent = new Intent(AboutPlatformActivity.this, WebActivity.class);
                intent.putExtra(WebActivity.TITLE, "微广优品协议");
                intent.putExtra(WebActivity.ACTION_URL, "https://wap.mohuyoupin.com/registration_agreement.html");
                startActivity(intent);
                break;
        }
    }

    private void saveImage() {
        platformImage.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Tools.KeepBitmap(platformImage, AboutPlatformActivity.this);
                return true;
            }
        });
    }

    private void copy(TextView textView) {
        ClipboardManager cmb = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        cmb.setText(textView.getText().toString()); //将内容放入粘贴管理器,在别的地方长按选择"粘贴"即可
        Toast.makeText(this, "复制成功", Toast.LENGTH_SHORT).show();
    }
}
